using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Graphics;

namespace new_OX
{
	[Activity (Label = "new_OX", MainLauncher = true)]
	public class Activity1 : Activity, View.IOnTouchListener
	{
		ViewHandler ViewHnd;
		protected override void OnCreate (Bundle bundle)
		{
			RequestWindowFeature(WindowFeatures.NoTitle);
			Window.SetFlags(WindowManagerFlags.Fullscreen,WindowManagerFlags.Fullscreen);
			base.OnCreate (bundle);
			ViewHnd = new ViewHandler(this);
			// Set our view from the "main" layout resource
			SetContentView (ViewHnd);
			ViewHnd.SetOnTouchListener(this);
			Settings.ChangeField(Field.S);
			//ViewHnd.SetBackgroundColor(Color.Azure);
			//ViewHnd.SetBackgroundResource("Untitled-1.png");
						//int pad = resources.getDimensionPixelSize(R.dimen.linear_layout_padding);
            //ViewHnd.setBackgroundResource(R.drawable.entry_bg_with_image);
          //  ViewHnd.setPadding(pad, pad, pad, pad);
						//ViewHnd.SetPadding();
			//ViewHnd.SetOnTouchListener(this);
			const int cx = -3, cy = 4;
			
            Point P = new Point(0, 0);
            int h = 0;
            for (int i = 0; i < Settings.r; i++)
                for (int j = 1; j < 2 + 2 * i; j++)
                {CellArray[h] = new Cell(12 + j - i - 1 + cx,i + 1 + cy); h++; }
            //
            for (int i = 0; i < 2 * Settings.r + 1; i++) { CellArray[h] = new Cell(1 + i + cx + Settings.dr,12 + cy - Settings.dr); h++; }
            int g = Settings.r + 1;
            for (int i = Settings.r; i > 0; i--)
            {
                g++;
                for (int j = 2; j < 1 + 2 * i; j++)
                { CellArray[h] = new Cell(12 + j - i - 1 + cx,g + cy); h++; }
            }


		}

		public int SearchCell(int x, int y)
        {
            int i = 0;
            for (i = 0; i < Settings.n; i++)
            {
                if ((x == CellArray[i].GetCellXY().X) && (y == CellArray[i].GetCellXY().Y) ) break;
            };

            return i;
        }

		public bool OnTouch(View v, MotionEvent e)
        {
            switch (e.Action)
            {
                case MotionEventActions.Down:
				GNumber1 = SearchCell((int)Math.Round(e.GetX()/s) , (int)Math.Round(e.GetY()/s) );
                    break;
                case MotionEventActions.Up:
                GetLocalMousePos.X = e.GetX();
				GetLocalMousePos.Y = e.GetY();
               if (validCell(GNumber1)) MainImplementation(GNumber1);

				ViewHnd.Invalidate();
                    break;
            }

            return true;
        }

        public enum Stick { T, L, All, Empty }
        public  const int s = 25;
        public const int initial = 265;
        //public const int n = initial - 84;
		//public int r = 2;
        public static int GNumber1 = 0;
        public static Cell[] CellArray = new Cell[initial];

		public enum Field {L = 11, M = 9, S = 7};

		public static Point GetLocalMousePos = new Point(0,0);

        public static class Settings
        {
            public static void ChangeField(Field e)
             {
                 CellField = e;
                 row = (int)CellField;
                 number = (row + 1) * (row + 1) + row * row;
             }
            public static int r { get { return row; } }
            public static int dr { get { return 11 - row; } }
            public static int n { get { return number; } }
            private static int number = 265;
            private static int row = 11;
            private static Field CellField;
        }

		public static int SearchCell(Point P)
        {
            int i = 0;
            for (i = 0; i < Settings.n; i++)
            {
                if ((P.X == CellArray[i].GetCellXY().X)&&(P.Y == CellArray[i].GetCellXY().Y)) break;
            };

            return i;
        }

		private static bool validCell(int Number1) { return ((Number1 != Settings.n) && (Number1 != 0) && (Number1 != Settings.n) && (Number1 != Math.Round(Settings.n / 2 + Math.Sqrt(Settings.n / 2))) && (Number1 != (Settings.n - 1)) && (Number1 != Math.Round(Settings.n / 2 - Math.Sqrt(Settings.n / 2)))); }

		private static void DrawSomething()
        {
            CellArray[0].ChangeCellState(Cell.Player);
            CellArray[(int)Math.Round(Settings.n / 2 - Math.Sqrt(Settings.n / 2))].ChangeCellState(Cell.Player);
            CellArray[Settings.n - 1].ChangeCellState(Cell.Player);
            CellArray[(int)Math.Round(Settings.n / 2 + Math.Sqrt(Settings.n / 2))].ChangeCellState(Cell.Player);

            CellArray[(int)Math.Round(Settings.n / 2 + Math.Sqrt(Settings.n / 2))].SetStick(Stick.L);
            CellArray[2].SetStick(Stick.T);
            CellArray[(int)Math.Round(Settings.n / 2 - Math.Sqrt(Settings.n / 2)) + 1].SetStick(Stick.L);
            CellArray[Settings.n - 1].SetStick(Stick.T);
        }

		private static bool side(int Number, int No)
        {
            switch (No)
            {
                case 1: return ((Math.Floor(Math.Sqrt(Number)) == Math.Sqrt(Number)) && (Number <= Math.Round(Settings.n / 2 - Math.Sqrt(Settings.n / 2))));
                case 2: return ((Math.Floor(Math.Sqrt(Number + 1)) == Math.Sqrt(Number + 1)) && (Number <= Math.Round(Settings.n / 2 + Math.Sqrt(Settings.n / 2)) - 2));
                case 3: return ((Math.Floor(Math.Sqrt(Settings.n - Number)) == Math.Sqrt(Settings.n - Number)) && (Number >= Math.Round(Settings.n / 2 + Math.Sqrt(Settings.n / 2))));
                case 4: return ((Math.Floor(Math.Sqrt(Settings.n - Number - 1)) == Math.Sqrt(Settings.n - Number - 1)) && (Number >= (Settings.n - (10 - Settings.dr) * (10 - Settings.dr)) - 1)); 
                default:  return false;
            }
        }

			private void MainImplementation(int Number1)
            {
            int Number2 = SearchCell(new Point(CellArray[Number1].GetCellXY().X, CellArray[Number1].GetCellXY().Y + 1));
            int Number3 = SearchCell(new Point(CellArray[Number1].GetCellXY().X, CellArray[Number1].GetCellXY().Y - 1));
            int Number4 = SearchCell(new Point(CellArray[Number1].GetCellXY().X, CellArray[Number1].GetCellXY().Y + 2));
            {
                if (((CellArray[Number1].GetCellXY().X > GetLocalMousePos.X / s) && (GetLocalMousePos.Y / s <= CellArray[Number1].GetCellXY().Y + s) && (GetLocalMousePos.Y / s >= CellArray[Number1].GetCellXY().Y)) && !side(Number1, 1) && !side(Number1, 3))
                    CellArray[Number1].SetStick(Stick.L );
                if (((CellArray[Number1].GetCellXY().Y > GetLocalMousePos.Y / s) && (GetLocalMousePos.X / s <= CellArray[Number1].GetCellXY().X + s) && (GetLocalMousePos.X / s >= CellArray[Number1].GetCellXY().X)) && !side(Number1, 1) && !side(Number1, 2))
                    CellArray[Number1].SetStick(Stick.T );
                if (((CellArray[Number1].GetCellXY().Y < GetLocalMousePos.Y / s) && (GetLocalMousePos.X / s <= CellArray[Number1].GetCellXY().X + s) && (GetLocalMousePos.X / s >= CellArray[Number1].GetCellXY().X)) && !side(Number1, 3) && !side(Number1, 4))
                    CellArray[Number2].SetStick(Stick.T );
                else if (((CellArray[Number1].GetCellXY().X < GetLocalMousePos.X / s) && (GetLocalMousePos.Y / s <= CellArray[Number1].GetCellXY().Y + s) && (GetLocalMousePos.Y / s >= CellArray[Number1].GetCellXY().Y)) && !side(Number1, 2) && !side(Number1, 4))
                    CellArray[Number1 + 1].SetStick(Stick.L );
            }
            bool forCell1 = false, forCell2 = false, forCell3 = false, forCell1p1 = false, forCell1m1 = false;

            if (!side(Number1, 1) && !side(Number1, 2) && !side(Number1, 3) && !side(Number1, 4))
            {

                forCell1 = ((CellArray[Number1].GetStick() == Stick.All) && (CellArray[Number1 + 1].GetStick() == Stick.L || CellArray[Number1 + 1].GetStick() == Stick.All) && (CellArray[Number2].GetStick() == Stick.T || CellArray[Number2].GetStick() == Stick.All));
                forCell1p1 = ((CellArray[Number1 + 1].GetStick() == Stick.All) && (CellArray[Number1 + 2].GetStick() == Stick.L || CellArray[Number1 + 2].GetStick() == Stick.All) && (CellArray[Number2 + 1].GetStick() == Stick.T || CellArray[Number2 + 1].GetStick() == Stick.All));
                forCell2 = ((CellArray[Number2].GetStick() == Stick.All) && (CellArray[Number2 + 1].GetStick() == Stick.L || CellArray[Number2 + 1].GetStick() == Stick.All) && (CellArray[Number4].GetStick() == Stick.T || CellArray[Number4].GetStick() == Stick.All));
                forCell3 = ((CellArray[Number3].GetStick() == Stick.All) && (CellArray[Number3 + 1].GetStick() == Stick.L || CellArray[Number3 + 1].GetStick() == Stick.All) && (CellArray[Number1].GetStick() == Stick.T || CellArray[Number1].GetStick() == Stick.All));
                forCell1m1 = ((CellArray[Number1 - 1].GetStick() == Stick.All) && (CellArray[Number1].GetStick() == Stick.L || CellArray[Number1].GetStick() == Stick.All) && (CellArray[Number2 - 1].GetStick() == Stick.T || CellArray[Number2 - 1].GetStick() == Stick.All));

                if (Number1 == Math.Round(Settings.n / 2 + Math.Sqrt(Settings.n / 2)) - 2)
                {
                    forCell2 = CellArray[Number2].GetStick() == Stick.All;
                    forCell3 = ((CellArray[Number3 ].GetStick() == Stick.L) && (CellArray[Number1].GetStick() == Stick.T || CellArray[Number1].GetStick() == Stick.All));
                }

                if (Number1 == Math.Round(Settings.n / 2 - Math.Sqrt(Settings.n / 2)) + 1)
                {
                    forCell3 = ((CellArray[Number1].GetStick() == Stick.T || CellArray[Number1].GetStick() == Stick.All) && (CellArray[Number3 + 1].GetStick() == Stick.L || CellArray[Number3 + 1].GetStick() == Stick.All));
                    forCell2 = ((CellArray[Number2].GetStick() == Stick.T) && (CellArray[Number2+1].GetStick() == Stick.L || CellArray[Number2+1].GetStick() == Stick.All));
                }

                if (Number1 == (Settings.n - 3))
                {
                    forCell1m1 = ((CellArray[Number1 - 1].GetStick() == Stick.T) && (CellArray[Number1].GetStick() == Stick.L || CellArray[Number1].GetStick() == Stick.All));
                    forCell1p1 = (CellArray[Number1 + 1].GetStick() == Stick.All);
                };

                if (side(Number1 - 1, 1))
                {
                    forCell3 = ((CellArray[Number1].GetStick() == Stick.T || CellArray[Number1].GetStick() == Stick.All) && (CellArray[Number3 + 1].GetStick() == Stick.L || CellArray[Number3 + 1].GetStick() == Stick.All));
                    forCell1m1 = ((CellArray[Number1].GetStick() == Stick.L || CellArray[Number1].GetStick() == Stick.All) && (CellArray[Number2 - 1].GetStick() == Stick.T || CellArray[Number2 - 1].GetStick() == Stick.All));
                }

                if (side(Number1 - 1, 3) && !(Number1 == (Settings.n - 3)))
                {
                    forCell2 = ((CellArray[Number2].GetStick() == Stick.T) && (CellArray[Number2 + 1].GetStick() == Stick.L || CellArray[Number2 + 1].GetStick() == Stick.All));
                    forCell1m1 = ((CellArray[Number1].GetStick() == Stick.L || CellArray[Number1].GetStick() == Stick.All) && (CellArray[Number1 - 1].GetStick() == Stick.T || CellArray[Number1 - 1].GetStick() == Stick.All));
                }

                if (side(Number1 + 1, 2))
                {
                    forCell3 = ((CellArray[Number1].GetStick() == Stick.T || CellArray[Number1].GetStick() == Stick.All) && (CellArray[Number3].GetStick() == Stick.L));
                    forCell1p1 = ((CellArray[Number2 + 1].GetStick() == Stick.T || CellArray[Number2 + 1].GetStick() == Stick.All) && (CellArray[Number1 + 1].GetStick() == Stick.L));
                }

                if (side(Number1 + 1, 4) && !(Number1 == (Settings.n - 3)))
                {
                    forCell2 = ((CellArray[Number2].GetStick() == Stick.All));
                    forCell1p1 = ((CellArray[Number1 + 1].GetStick() == Stick.All));
                }

                if (forCell1 && forCell2 && (CellArray[Number1].GetCellState() == Cell.CellState.Empty) && (CellArray[Number2].GetCellState() == Cell.CellState.Empty))
                {
                    CellArray[Number1].ChangeCellState(Cell.Player );
                    Cell.Player = !Cell.Player;
                    CellArray[Number2].ChangeCellState(Cell.Player );
                }

                if (forCell1 && forCell1p1 && (CellArray[Number1].GetCellState() == Cell.CellState.Empty) && (CellArray[Number1 + 1].GetCellState() == Cell.CellState.Empty))
                {
                    CellArray[Number1].ChangeCellState(Cell.Player );
                    Cell.Player = !Cell.Player;
                    CellArray[Number1 + 1].ChangeCellState(Cell.Player );
                }

                if (forCell1 && forCell3 && (CellArray[Number1].GetCellState() == Cell.CellState.Empty) && (CellArray[Number3].GetCellState() == Cell.CellState.Empty))
                {
                    CellArray[Number1].ChangeCellState(Cell.Player );
                    Cell.Player = !Cell.Player;
                    CellArray[Number3].ChangeCellState(Cell.Player );
                }

                if (forCell1 && forCell1m1 && (CellArray[Number1].GetCellState() == Cell.CellState.Empty) && (CellArray[Number1 - 1].GetCellState() == Cell.CellState.Empty))
                {
                    CellArray[Number1].ChangeCellState(Cell.Player );
                    Cell.Player = !Cell.Player;
                    CellArray[Number1 - 1].ChangeCellState(Cell.Player );
                }


            }
            else
            {
                if (side(Number1, 1))
                {
                    forCell1 = ((CellArray[Number1 + 1].GetStick() == Stick.L || CellArray[Number1 + 1].GetStick() == Stick.All) && (CellArray[Number2].GetStick() == Stick.T || CellArray[Number2].GetStick() == Stick.All));
                    forCell2 = ((CellArray[Number2].GetStick() == Stick.All) && (CellArray[Number2 + 1].GetStick() == Stick.L || CellArray[Number2 + 1].GetStick() == Stick.All) && (CellArray[Number4].GetStick() == Stick.T || CellArray[Number4].GetStick() == Stick.All));
                    forCell1p1 = ((CellArray[Number1 + 1].GetStick() == Stick.All) && (CellArray[Number1 + 2].GetStick() == Stick.L || CellArray[Number1 + 2].GetStick() == Stick.All) && (CellArray[Number2 + 1].GetStick() == Stick.T || CellArray[Number2 + 1].GetStick() == Stick.All));
                    if (forCell1 && forCell2 && (CellArray[Number1].GetCellState() == Cell.CellState.Empty) && (CellArray[Number2].GetCellState() == Cell.CellState.Empty))
                    {
                        CellArray[Number1].ChangeCellState(Cell.Player );
                        Cell.Player = !Cell.Player;
                        CellArray[Number2].ChangeCellState(Cell.Player );
                    }
                    if (forCell1 && forCell1p1 && (CellArray[Number1].GetCellState() == Cell.CellState.Empty) && (CellArray[Number1 + 1].GetCellState() == Cell.CellState.Empty))
                    {
                        CellArray[Number1].ChangeCellState(Cell.Player );
                        Cell.Player = !Cell.Player;
                        CellArray[Number1 + 1].ChangeCellState(Cell.Player );
                    }
                };
                if (side(Number1, 2))
                {
                    forCell1 = ((CellArray[Number1].GetStick() == Stick.L) && (CellArray[Number2].GetStick() == Stick.T || CellArray[Number2].GetStick() == Stick.All));
                    forCell2 = ((CellArray[Number2].GetStick() == Stick.All) && (CellArray[Number2 + 1].GetStick() == Stick.L || CellArray[Number2 + 1].GetStick() == Stick.All) && (CellArray[Number4].GetStick() == Stick.T || CellArray[Number4].GetStick() == Stick.All));
                    forCell1m1 = ((CellArray[Number1 - 1].GetStick() == Stick.All) && (CellArray[Number1].GetStick() == Stick.L || CellArray[Number1].GetStick() == Stick.All) && (CellArray[Number2 - 1].GetStick() == Stick.T || CellArray[Number2 - 1].GetStick() == Stick.All));
                    if (forCell1 && forCell2 && (CellArray[Number1].GetCellState() == Cell.CellState.Empty) && (CellArray[Number2].GetCellState() == Cell.CellState.Empty))
                    {
                        CellArray[Number1].ChangeCellState(Cell.Player );
                        Cell.Player = !Cell.Player;
                        CellArray[Number2].ChangeCellState(Cell.Player );
                    }
                    if (forCell1 && forCell1m1 && (CellArray[Number1].GetCellState() == Cell.CellState.Empty) && (CellArray[Number1 - 1].GetCellState() == Cell.CellState.Empty))
                    {
                        CellArray[Number1].ChangeCellState(Cell.Player );
                        Cell.Player = !Cell.Player;
                        CellArray[Number1 - 1].ChangeCellState(Cell.Player );
                    }

                };
                if (side(Number1, 3))
                {
                    int Number2p1 = SearchCell(new Point(CellArray[Number1].GetCellXY().X + 1, CellArray[Number1].GetCellXY().Y + 1));
                    forCell1 = ((CellArray[Number1].GetStick() == Stick.T) && (CellArray[Number1 + 1].GetStick() == Stick.L || CellArray[Number1 + 1].GetStick() == Stick.All));
                    forCell3 = ((CellArray[Number3].GetStick() == Stick.All) && (CellArray[Number3 + 1].GetStick() == Stick.L || CellArray[Number3 + 1].GetStick() == Stick.All) && (CellArray[Number1].GetStick() == Stick.T || CellArray[Number1].GetStick() == Stick.All));
                    forCell1p1 = ((CellArray[Number1 + 1].GetStick() == Stick.All) && (CellArray[Number1 + 2].GetStick() == Stick.L || CellArray[Number1 + 2].GetStick() == Stick.All) && (CellArray[Number2p1].GetStick() == Stick.T));
                    if (forCell1 && forCell1p1 && (CellArray[Number1].GetCellState() == Cell.CellState.Empty) && (CellArray[Number1 + 1].GetCellState() == Cell.CellState.Empty))
                    {
                        CellArray[Number1].ChangeCellState(Cell.Player );
                        Cell.Player = !Cell.Player;
                        CellArray[Number1 + 1].ChangeCellState(Cell.Player );
                    }
                    if (forCell1 && forCell3 && (CellArray[Number1].GetCellState() == Cell.CellState.Empty) && (CellArray[Number3].GetCellState() == Cell.CellState.Empty))
                    {
                        CellArray[Number1].ChangeCellState(Cell.Player );
                        Cell.Player = !Cell.Player;
                        CellArray[Number3].ChangeCellState(Cell.Player );
                    }
                };
                if (side(Number1, 4))
                {
                    int Number2m1 = SearchCell(new Point(CellArray[Number1].GetCellXY().X - 1, CellArray[Number1].GetCellXY().Y + 1));
                    forCell1 = (CellArray[Number1].GetStick() == Stick.All);
                    forCell1m1 = ((CellArray[Number1 - 1].GetStick() == Stick.All) && (CellArray[Number1].GetStick() == Stick.L || CellArray[Number1].GetStick() == Stick.All) && (CellArray[Number2m1].GetStick() == Stick.T || CellArray[Number2m1].GetStick() == Stick.All));
                    forCell3 = ((CellArray[Number3].GetStick() == Stick.All) && (CellArray[Number3 + 1].GetStick() == Stick.L || CellArray[Number3 + 1].GetStick() == Stick.All) && (CellArray[Number1].GetStick() == Stick.T || CellArray[Number1].GetStick() == Stick.All));
                    if (forCell1 && forCell3 && (CellArray[Number1].GetCellState() == Cell.CellState.Empty) && (CellArray[Number3].GetCellState() == Cell.CellState.Empty))
                    {
                        CellArray[Number1].ChangeCellState(Cell.Player );
                        Cell.Player = !Cell.Player;
                        CellArray[Number3].ChangeCellState(Cell.Player );
                    }
                    if (forCell1 && forCell1m1 && (CellArray[Number1].GetCellState() == Cell.CellState.Empty) && (CellArray[Number1 - 1].GetCellState() == Cell.CellState.Empty))
                    {
                        CellArray[Number1].ChangeCellState(Cell.Player );
                        Cell.Player = !Cell.Player;
                        CellArray[Number1 - 1].ChangeCellState(Cell.Player );
                    }

                };

            }

            if (forCell1)
            {
                CellArray[Number1].ChangeCellState(Cell.Player );
            }

            if (forCell1p1)
            {
                CellArray[Number1 + 1].ChangeCellState(Cell.Player );
            }

            if (forCell3)
            {
                CellArray[Number3].ChangeCellState(Cell.Player );
            }

            if (forCell1m1)
            {
                CellArray[Number1 - 1].ChangeCellState(Cell.Player );

            }

            if (forCell2)
            {
                CellArray[Number2].ChangeCellState(Cell.Player );
            }
           

        }
		

        public class Cell
        {
			public Cell(float x,float y) { CellXY.X=x; CellXY.Y = y; CS = CellState.Empty; CellStick = Stick.Empty; ClearQuantity(); }
            public Cell() { CellXY.X = 0; CellXY.Y = 0; CS = CellState.Empty; CellStick = Stick.Empty; ClearQuantity();  }

            public enum CellState { X, O, Empty };

            public void SetStick(Stick C)
            {
                if (CellStick == Stick.Empty)
                {
                    CellStick = C;
                    Player = !Player;
                };

                if (CellStick == Stick.L && C == Stick.T)
                {

                    CellStick = Stick.All;

                    Player = !Player;
                }

                if (CellStick == Stick.T && C == Stick.L)
                {
                    CellStick = Stick.All;

                    Player = !Player;
                }
                

            }
			
            public void drawCell(Canvas canvas)
            {
                switch (CellStick)
                {
                    case Stick.All: canvas.DrawLine( CellXYToFormXY().X, CellXYToFormXY().Y, CellXYToFormXY().X + s, CellXYToFormXY().Y, mPaint);
                        canvas.DrawLine( CellXYToFormXY().X,  CellXYToFormXY().Y, CellXYToFormXY().X, CellXYToFormXY().Y + s, mPaint);
                        break;
                    case Stick.L: canvas.DrawLine( CellXYToFormXY().X, CellXYToFormXY().Y, CellXYToFormXY().X, CellXYToFormXY().Y + s, mPaint);
                        break;
                    case Stick.T: canvas.DrawLine( CellXYToFormXY().X, CellXYToFormXY().Y, CellXYToFormXY().X + s, CellXYToFormXY().Y, mPaint);
                        break;
                }
                if (CS == CellState.X)
                {
                    canvas.DrawLine(CellXYToFormXY().X + s / 10+2, CellXYToFormXY().Y + s / 10+2, CellXYToFormXY().X + s - s / 10-2, CellXYToFormXY().Y + s - s / 10-2, mPaint);
                    canvas.DrawLine(CellXYToFormXY().X + s / 10+2, CellXYToFormXY().Y - s / 10 -2 + s, CellXYToFormXY().X + s - s / 10-2, CellXYToFormXY().Y +  s / 10+2, mPaint);
                
                }
					if (CS == CellState.O) canvas.DrawCircle(CellXYToFormXY().X+s/2,CellXYToFormXY().Y+s/2, s/2 - s/5, mPaint); //canvas.DrawArc( new RectF(CellXYToFormXY().X + s / 10, CellXYToFormXY().Y + s / 10, CellXYToFormXY().X +(s - 2 * s / 10), CellXYToFormXY().Y + (s - 2 * s / 10)),0,360, false, mPaint);
            }

			
            public Stick GetStick() { return CellStick; }

            public void ChangeCellState(bool B)
            {
                if (CS == CellState.Empty)
                {
                    CS = (B) ? CellState.X  : CellState.O;
                   
                    if(B) QuantityXO[1]++; else QuantityXO[0]++;
                    Player = !Player;
                }
            }


            public void ClearQuantity()
            {
                QuantityXO[1] = 0;
                QuantityXO[0] = 0;
            }

            public CellState GetCellState() { return CS; }
            public static bool Player = true;
            public Point CellXYToFormXY() {return new Point(CellXY.X * s, CellXY.Y * s);}
            public Point GetCellXY() { return CellXY; }
            protected Point CellXY = new Point(0,0);
            protected Stick CellStick;
            protected CellState CS;
            public static int[] QuantityXO = new int[2];

        }
	
		public static Paint mPaint;
		

		public class Point
		{
			public Point(float x, float y) {X = x; Y = y;}
			public float X=0, Y=0;
		}

		public class ViewHandler : View
		{
		//public static Paint mPaint;
			
			public ViewHandler(Context context) : base (context)
			{
				Focusable = true;
				mPaint = new Paint ();
				mPaint.Color = Color.White;
				mPaint.SetStyle(Paint.Style.Stroke);

				//mPaint.AntiAlias = true;
			}

			protected override void OnDraw (Canvas canvas)
			{

				DrawSomething ();

				/*Cell c = new Cell(5,5);
				c.ChangeCellState(true);
				c.SetStick(Stick.All);
				c.drawCell(canvas);*/
				for (int i = 0; i < Settings.n; i++) Activity1.CellArray[i].drawCell(canvas);

				// (int i = 0; i < n; i++)
				//	Activity1.CellArray[i].drawCell (canvas);
				
				//	canvas.Restore ();
				
			}

		}

	}
}


